package cn.duli.myvideo.controller;

import cn.duli.myvideo.pojo.CollectTv;
import cn.duli.myvideo.service.CollectTvService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/collectTv")
public class CollectTvController {

    @Resource
    private CollectTvService collectTvService;

    /**
     * 分页查询所有收藏电视剧列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/findAll")
    public PageInfo<CollectTv> findAll(
            @RequestParam(defaultValue = "1") int pageNo,
            @RequestParam(defaultValue = "2") int pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<CollectTv> pageInfo = new PageInfo<>(collectTvService.findAll());
        return pageInfo;
    }


    /**
     * 根据电视剧id查找此电视剧的总数
     * @param tvId
     * @return
     */
    @GetMapping("/findCountByTvId/{tvId}")
    public Integer findCountByTvId(@PathVariable("tvId") Integer tvId){
        return collectTvService.findCountByTvId(tvId);
    }

    /**
     * 根据用户id查看该用户收藏的电视剧
     * @param uId
     * @return
     */
    @GetMapping("/findByUserId/{uId}")
    public List<CollectTv> findByUserId(@PathVariable("uId") Integer uId){
        return collectTvService.findByUserId(uId);
    }

    /**
     * 根据电视剧id查看该电视剧的收藏列表
     * @param tvId
     * @return
     */
    @GetMapping("/findByTvId/{tvId}")
    public List<CollectTv> findByTvId(@PathVariable("tvId") Integer tvId){
        return collectTvService.findByTvId(tvId);
    }

    /**
     * 新增收藏电视剧
     * @param collectTv
     */
    @PostMapping("/save")
    public void save(@RequestBody CollectTv collectTv){
        collectTvService.save(collectTv);
    }

    /**
     * 删除收藏电视剧
     * @param ctvId
     */
    @RequestMapping("/deleteById/{ctvId}")
    public void deleteById(@PathVariable("ctvId") Integer ctvId){
        collectTvService.deleteById(ctvId);
    }

}
